<template>
	<view>
		<c-bottom-dialog ref="bottomRef" :title='title'>
			<template v-if="title==='操作'">
				<view class="user-action" v-if="isUser">
					<view class="user-action-item fx-colum-center" @click="delTalk">
						<image src="/static/jubao.png" mode="widthFix" class="user-action-img"></image>
						<view class="">删除</view>
					</view>
				</view>
				<view class="user-action fx-center" v-else>
					<view class="user-action-item fx-colum-center" @click="followUser">
						<image src="/static/guanzhu.png" mode="widthFix" class="user-action-img"></image>
						<view class="" v-if="info.user">{{info.user.followed ? '取消关注' : '关注'}}</view>
					</view>
					<view class="user-action-item fx-colum-center" @click="reportUser">
						<image src="/static/jubao.png" mode="widthFix" class="user-action-img"></image>
						<view class="">举报</view>
					</view>
				</view>
			</template>
			<template v-if="title==='分享'">
				<view class="user-action fx-center">

					<view class="user-action-item">
						<van-button open-type="share"
							custom-style="font-size: 26rpx;color: #5C5F66;border:none;height:200rpx">
							<view class="fx-colum-center">
								<!-- <image src="/static/share_wx.png" mode="widthFix" class="user-action-img"></image> -->
								<view class="">分享给好友</view>
							</view>
						</van-button>
					</view>
					<view class="user-action-item">
						<van-button open-type="share"
							custom-style="font-size: 26rpx;color: #5C5F66;border:none;height:200rpx">
							<view class="fx-colum-center">
								<!-- <image src="/static/share_pyq.png" mode="widthFix" class="user-action-img"></image> -->
								<view class="">转发朋友圈</view>
							</view>
						</van-button>

					</view>

				</view>
			</template>
		</c-bottom-dialog>
	</view>
</template>

<script>
	export default {
		name: "c-user-opration",
		props: {
			title: {
				typeof: String,
				default: '操作'
			},
			// 用户id
			userId: {
				typeof: String || Number,
				default: ''
			},
			// 帖子详情
			info: {
				typeof: String || Number,
				default: ''
			}
		},
		data() {
			return {
				isUser: false, //是否是用户自己的帖子
			};
		},
		methods: {
			show() {
				this.isUser = (this.userId == uni.getStorageSync("userId") ? true : false)
				this.$refs.bottomRef.show()
			},
			// 删除帖子
			delTalk() {
				if (this.$store.state.islogin) {
					uni.showLoading({
						title: '删除中...'
					})
					this.$api
						.requst('/gwc/topics/delete', {
							id: this.info.id,
						}, 'POST')
						.then((res) => {
							this.$api.showError('删除成功！')
							this.$refs.bottomRef.close()
							setTimeout(() => {
								this.$emit('refrash')
							}, 500)

						})
				} else {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}

			},
			// 关注用户
			followUser() {
				if (this.$store.state.islogin) {
					this.$api
						.requst('/gwc/follows', {
							action: this.info.user.followed ? 0 : 1, //0表示取消关注，1表示关注
							obj_type: 'User',
							obj_id: this.info.user.id
						}, 'POST')
						.then((res) => {
							this.$api.showError(this.info.user.followed ? '已取消关注' : '关注成功')
							this.info.user.followed = !this.info.user.followed
							this.$refs.bottomRef.close()
							this.$emit('refrashUser')
						})
				} else {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}
			},
			// 举报用户
			reportUser() {
				if (this.$store.state.islogin) {
					this.$api
						.requst(`/gwc/topics/${this.info.id}/report`, {
							id: this.info.id
						}, 'POST')
						.then((res) => {
							this.$api.showError('操作成功！')
							this.$refs.bottomRef.close()
						})
				} else {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.user-action {
		padding: 24rpx 0;
		color: #161616;
		font-size: 26rpx;

		.user-action-item {
			flex: 1;
			text-align: center;
		}

		.user-action-img {
			width: 100rpx;
			height: 100rpx;
			margin-bottom: 28rpx;
		}
	}
</style>